<template>
  <div class="app-container">
    <div class="project-list-view">
      <el-table :data="tableData3"
                border
                style="width: 100%"
                :row-key="tableData3.id">
        <el-table-column prop="id"
                         label="ID"
                         width="100">
        </el-table-column>
        <el-table-column prop="pro_id"
                         label="项目ID"
                         width="100">
        </el-table-column>
        <el-table-column prop="username"
                         label="发布者"
                         width="150">
        </el-table-column>
        <el-table-column prop="projectTitle"
                         label="评论的项目标题">
        </el-table-column>

        <el-table-column prop="content"
                         label="评论内容">
        </el-table-column>
        <el-table-column prop="userTag"
                         label="用户标签"
                         width="100">
        </el-table-column>
        <!-- <el-table-column prop="datatime"
                         label="发布时间"
                         width="100">
        </el-table-column> -->
        <el-table-column prop="delete"
                         label="删除"
                         width="80">
          <template slot-scope="scope">
            <el-button @click="handleDelete(scope.$index)"
                       type="danger"
                       plain
                       size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import {
  getProjectList,
  updateProjectSelected,
  updateProjectHot,
  delProject,
} from '@/api/projectList'
export default {
  name: 'CommunicationList',
  computed: {},
  data() {
    return {
      tableData3: [],
      projectSelected: '0',
      projectHot: '0',
    }
  },
  methods: {
    // 获取项目信息
    getProjectInfo: function () {
      this.tableData3 = [
        {
          id: 1,
          pro_id: 1,
          projectTitle: '前端获取电池信息方案',
          content: 'vue3+vite已经撸了一个大项目了',
          username: '前端BUG工程师',
          // datatime: '2023-2-9 13:28:46',
          userTag: '前端',
        },
        {
          id: 2,
          pro_id: 1,
          projectTitle: '前端获取电池信息方案',
          content: '先码再看',
          username: '用户3681784879333',
          // datatime: '2023-2-9 13:28:46',
          userTag: '前端',
        },
        {
          id: 3,
          pro_id: 1,
          projectTitle: '前端获取电池信息方案',
          content: '6666',
          username: 'Andy屎大颗',
          // datatime: '2023-2-9 13:28:46',
          userTag: 'ctrl+CorV资深前端开发',
        },
        {
          id: 4,
          pro_id: 1,
          projectTitle: '前端获取电池信息方案',
          content: '问个问题，多个props、computed、watch 这种怎么写？',
          username: '韦德约科维奇',
          // datatime: '2023-2-9 13:28:46',
          userTag: '前端',
        },
      ]
    },
    // 删除项目
    handleDelete: function (index) {
      console.log('删除')
      this.tableData3.splice(index, 1)
      // this.tableData3.length =
      this.$message({
        showClose: true,
        message: '标签删除成功',
        type: 'success',
      })
    },
    // 项目精选开关
    handleChangeSelected: function (projectId) {
      updateProjectSelected({
        pro_id: projectId,
        selected: this.projectSelected,
      }).then((res) => {
        if (res.data.status == 200) {
          this.$message({
            showClose: true,
            message: res.data.data,
            type: 'success',
          }),
            this.getProjectInfo()
        } else {
          this.$message({
            showClose: true,
            message: res.data.data,
            type: 'warning',
          })
        }
      })
    },
    // 项目热门开关
    handleChangeHot: function (projectId) {
      updateProjectHot({
        pro_id: projectId,
        hot: this.projectHot,
      }).then((res) => {
        if (res.data.status == 200) {
          this.$message({
            showClose: true,
            message: res.data.data,
            type: 'success',
          }),
            this.getProjectInfo()
        } else {
          this.$message({
            showClose: true,
            message: res.data.data,
            type: 'warning',
          })
        }
      })
    },
  },
  beforeMount() {
    this.getProjectInfo()
  },
}
</script>

<style lang="scss"></style>